package com.flxz.forum.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flxz.common.annotation.Log;
import com.flxz.common.core.controller.BaseController;
import com.flxz.common.core.domain.AjaxResult;
import com.flxz.common.enums.BusinessType;
import com.flxz.forum.domain.ForumReply;
import com.flxz.forum.service.IForumReplyService;
import com.flxz.common.utils.poi.ExcelUtil;
import com.flxz.common.core.page.TableDataInfo;

/**
 * 讨论回复Controller
 * 
 * @author fl
 * @date 2025-09-14
 */
@RestController
@RequestMapping("/forum/reply")
public class ForumReplyController extends BaseController
{
    @Autowired
    private IForumReplyService forumReplyService;

    /**
     * 查询讨论回复列表
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:reply:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumReply forumReply)
    {
        startPage();
        List<ForumReply> list = forumReplyService.selectForumReplyList(forumReply);
        return getDataTable(list);
    }

    /**
     * 导出讨论回复列表
     */
    @PreAuthorize("@ss.hasPermi('forum:reply:export')")
    @Log(title = "讨论回复", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumReply forumReply)
    {
        List<ForumReply> list = forumReplyService.selectForumReplyList(forumReply);
        ExcelUtil<ForumReply> util = new ExcelUtil<ForumReply>(ForumReply.class);
        util.exportExcel(response, list, "讨论回复数据");
    }

    /**
     * 获取讨论回复详细信息
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:reply:query')")
    @GetMapping(value = "/{replyId}")
    public AjaxResult getInfo(@PathVariable("replyId") Long replyId)
    {
        return success(forumReplyService.selectForumReplyByReplyId(replyId));
    }

    /**
     * 新增讨论回复
     */
    @PreAuthorize("@ss.hasPermi('forum:reply:add')")
    @Log(title = "讨论回复", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumReply forumReply)
    {
        return toAjax(forumReplyService.insertForumReply(forumReply));
    }

    /**
     * 修改讨论回复
     */
    @PreAuthorize("@ss.hasPermi('forum:reply:edit')")
    @Log(title = "讨论回复", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumReply forumReply)
    {
        return toAjax(forumReplyService.updateForumReply(forumReply));
    }

    /**
     * 删除讨论回复
     */
    @PreAuthorize("@ss.hasPermi('forum:reply:remove')")
    @Log(title = "讨论回复", businessType = BusinessType.DELETE)
	@DeleteMapping("/{replyIds}")
    public AjaxResult remove(@PathVariable Long[] replyIds)
    {
        return toAjax(forumReplyService.deleteForumReplyByReplyIds(replyIds));
    }
}
